package com.java.myapp.serviceImpl;

import java.io.IOException;

import com.java.myapp.entity.FoodEntity;
import com.java.myapp.entity.SportEntity;
import com.java.myapp.entity.UserActivity;
import com.java.myapp.entity.UserEntity;
import com.java.myapp.entity.UserGoal;
import com.java.myapp.service.ActivityManager;
import com.java.myapp.service.UserService;
import com.java.myapp.service.UtilityEntityService;

public class ActivityManagerImpl implements ActivityManager {
	UserService userService=new UserServiceImpl();
	UtilityEntityService<UserActivity>utilityActivity=new UtilityEntityServiceImpl<>();
	public static UserEntity userEntity;
	@Override
	public void setUserGoal(UserGoal userGoal) {
		UtilityEntityService<UserGoal>utilityGoal=new UtilityEntityServiceImpl<>();
		utilityGoal.addObject(userGoal);
	}

	@Override
	public void addFoodEntity(FoodEntity foodEntity) {
		UtilityEntityService<FoodEntity> utilityFood=new UtilityEntityServiceImpl<FoodEntity>();
		utilityFood.addObject(foodEntity);
	}

	@Override
	public void eatFoodEntity(FoodEntity foodEntity) {
		utilityActivity.addObject(new UserActivity(userEntity.getUserId(),foodEntity,null));
	}

	@Override
	public void addSportEntity(SportEntity sportEntity) {
		UtilityEntityService<SportEntity> utilitySport=new UtilityEntityServiceImpl<>();
		utilitySport.addObject(sportEntity);
	}

	@Override
	public void playSportEntity(SportEntity sportEntity) {
		utilityActivity.addObject(new UserActivity(userEntity.getUserId(),null,sportEntity));
	}

	@Override
	public Double calculateCalEachDay() {
		return null;
	}

	@Override
	public UserEntity login(UserEntity userEntity) {
		try {
			return userService.login(userEntity);
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public Boolean logout(UserEntity userEntity) {
		try{
			userEntity=null;
			userService.logOut();
			return true;
		}catch(IOException e){
			return false;
		}
	}

	@Override
	public UserEntity loadUserIfExist() {
		return userService.getUserLogin();
	}

}
